package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.data.TableData;
import com.fr.data.TableDataException;
import com.fr.data.core.DataUtils;
import com.fr.report.script.Calculator;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TABLEDATAFIELDS extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    int i;
    if (paramArrayOfObject.length != 1)
      return Primitive.ERROR_NAME;
    FArray localFArray = new FArray();
    String str = paramArrayOfObject[0].toString();
    Calculator localCalculator = getCalculator();
    TableData localTableData = DataUtils.getTableData4Function(localCalculator, str);
    if (localTableData == null)
      return Primitive.NULL;
    try
    {
      for (i = 0; i < localTableData.getColumnCount(); ++i)
        localFArray.add(localTableData.getColumnName(i));
    }
    catch (TableDataException localTableDataException)
    {
      FRContext.getLogger().log(Level.WARNING, localTableDataException.getMessage(), localTableDataException);
    }
    return localFArray;
  }

  public Function.Type getType()
  {
    return Function.REPORT;
  }

  public String getCN()
  {
    return "TABLEDATAFIELDS(tableData):返回tableData中所有的字段名。\n备注:\n    先从报表数据集中查找，然后再从服务器数据集中查找，返回的是tableData的列名组成的数组。\n示例:TABLEDATAFIELDS(\"国家\")等于[名字,首都,大陆,面积,人口]";
  }

  public String getEN()
  {
    return "";
  }
}